package com.baizhi.llw.controller;

import com.baizhi.llw.dto.CommonPageDTO;
import com.baizhi.llw.dto.TwoPageDTO;
import com.baizhi.llw.entity.Category;
import com.baizhi.llw.service.CategoryService;
import com.baizhi.llw.vo.CategoryPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @ResponseBody
    @RequestMapping("/queryOnePage")
    public CategoryPageVO queryOnePage(@RequestBody CommonPageDTO commonPageDTO){
        return categoryService.queryOnePage(commonPageDTO.getPage(),commonPageDTO.getPageSize());
    }
    @ResponseBody
    @RequestMapping("/queryTwoPage")
    public CategoryPageVO queryTwoPage(@RequestBody TwoPageDTO commonPageDTO){
        return categoryService.queryTwoPage(commonPageDTO.getPage(),commonPageDTO.getPageSize(),commonPageDTO.getCategoryId());
    }
    @ResponseBody
    @RequestMapping("/delete")
    public void delete(@RequestBody Category category){
        categoryService.queryRemove(category);
    }
    @ResponseBody
    @RequestMapping("/add")
    public void add(@RequestBody Category category){
        categoryService.queryAdd(category);
    }
    @ResponseBody
    @RequestMapping("/queryById")
    public Category queryById(int id){
      return categoryService.queryOne(id);
    }
    @ResponseBody
    @RequestMapping("/update")
    public void update(@RequestBody Category c){
        categoryService.queryUpdate(c);
    }
}
